#ifndef INVENTORY
#define INVENTORY

/* Inventory
*************************************************************************************
*
*   Catalog of all items and their prices for sale
*
*	Max - 50
*	Should be initialized from .dat file (Invent.dat for driver)
*
*	Invent.dat format
*
*		product number | description | price | Taxable
*		<5 digits> <12 chars max, no blanks> <real> <T/N, T for taxable, N for not>
*		12345 hello_world 32.50 T
*
*************************************************************************************
*
*   Credits
*
*		Richard Rios
*		Aaron Solomon
*
*************************************************************************************
*/
	#include <fstream>

	#include "IndexedArray.h"
	#include "Product.h"

	using namespace std;
/*
*************************************************************************************/

class Inventory {
	/*************************************************************************************
	*
	*	Fields
	*/
	private:
		static const int MAX_PRODUCTS = 50;

		IndexedArray<Product*, MAX_PRODUCTS> products;

	public:
		static const int INVALID_INVENTORY_FILE = 1;

		IndexedArray<int, MAX_PRODUCTS - 1> duplicates;
	/*
	*************************************************************************************
	*
	*	Constructors
	*/
	public:
		Inventory(char* filename);
		/*
		*
		*   Description
		*   -----------------------
		*
		*		Takes filename of file that contains inventory data. Reads all items from that file
		*		and stores them into Products, which are in turn stored into an indexed array of
		*		Products.
		*
		*   Takes
		*   -----------------------
		*
		*		char* filename
		*			-	name of .dat file with inventory
		*
		*   Returns
		*   -----------------------
		*
		*       Initialized Inventory
		*
		*/

	/*
	*************************************************************************************
	*
	*	Destructor
	*/
		~Inventory();
		/*
		*
		*   Description
		*   -----------------------
		*
		*		Destroys each product in products
		*
		*   Takes
		*   -----------------------
		*
		*		nothing
		*
		*   Returns
		*   -----------------------
		*
		*       nothing
		*
		*/
	/*
	*************************************************************************************
	*
	*	Methods
	*/
	private:
		void getProducts(char* filename);
		/*
		*
		*   Description
		*   -----------------------
		*
		*       Retrieves all products from file. Goes over file line by line and passes those lines into
		*		the Product class. Each of these products are then stored into the products indexed array.
		*
		*		.dat file must have product ids sorted from least to greatest. If a product id is smaller than
		*		the last product id in the indexed array, the operation will fail and throw an error.
		*
		*   Takes
		*   -----------------------
		*
		*		nothing
		*
		*   Returns
		*   -----------------------
		*
		*       nothing
		*
		*/
	public:
		Product* find(int productId);
		/*
		*
		*   Description
		*   -----------------------
		*
		*       Searches for a product within the inventory given a product id. If the product wasn't found, returns
		*		0 (NULL pointer).
		*
		*		Uses binary search O(log n), not IndexedArray default search
		*
		*   Takes
		*   -----------------------
		*
		*		int productId
		*
		*   Returns
		*   -----------------------
		*
		*       Product* (product with product id)
		*
		*/
	/*
	*************************************************************************************/
}; //class Inventory

#endif